/**
  ******************************************************************************
  * File Name          : BMP280.h
  * Description        : This file provides code for the configuration
  *                      of the BMP280 instances.
  ******************************************************************************
  *
  * COPYRIGHT(c) 2017 STMicroelectronics
  *
  * Redistribution and use in source and binary forms, with or without modification,
  * are permitted provided that the following conditions are met:
  *   1. Redistributions of source code must retain the above copyright notice,
  *      this list of conditions and the following disclaimer.
  *   2. Redistributions in binary form must reproduce the above copyright notice,
  *      this list of conditions and the following disclaimer in the documentation
  *      and/or other materials provided with the distribution.
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
  *      may be used to endorse or promote products derived from this software
  *      without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  ******************************************************************************
  */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __BMP280_H
#define __BMP280_H
#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal.h"
     
#define BMP280_ADDRESS 0x76     
     
enum{  
   BMP280_REGISTER_DIG_T1  =       0x88,
   BMP280_REGISTER_DIG_T2  =       0x8A,
   BMP280_REGISTER_DIG_T3  =       0x8C,

   BMP280_REGISTER_DIG_P1  =       0x8E,
   BMP280_REGISTER_DIG_P2  =       0x90,
   BMP280_REGISTER_DIG_P3  =       0x92,
   BMP280_REGISTER_DIG_P4  =       0x94,
   BMP280_REGISTER_DIG_P5  =       0x96,
   BMP280_REGISTER_DIG_P6  =       0x98,
   BMP280_REGISTER_DIG_P7  =       0x9A,
   BMP280_REGISTER_DIG_P8  =       0x9C,
   BMP280_REGISTER_DIG_P9  =       0x9E,

   BMP280_REGISTER_CHIPID  =       0xD0,
   BMP280_REGISTER_VERSION =       0xD1,
   BMP280_REGISTER_SOFTRESET =     0xE0,
     
   BMP280_REGISTER_CAL26   =       0xE1,  // R calibration stored in 0xE1-0xF0
     
   BMP280_REGISTER_CONTROL  =      0xF4,
   BMP280_REGISTER_CONFIG    =     0xF5,
   BMP280_REGISTER_PRESSUREDATA =  0xF7,
   BMP280_REGISTER_TEMPDATA    =   0xFA,
};

typedef struct
{
  uint16_t dig_T1;
  int16_t  dig_T2;
  int16_t  dig_T3;

  uint16_t dig_P1;
  int16_t  dig_P2;
  int16_t  dig_P3;
  int16_t  dig_P4;
  int16_t  dig_P5;
  int16_t  dig_P6;
  int16_t  dig_P7;
  int16_t  dig_P8;
  int16_t  dig_P9;

  uint8_t  dig_H1;
  int16_t  dig_H2;
  uint8_t  dig_H3;
  int16_t  dig_H4;
  int16_t  dig_H5;
  int8_t   dig_H6;
} bmp280_calib_data;

enum {
    forceMode = 0x01,
    sleepMode = 0x00,
    normalMode = 0x11,
};

uint8_t SET_BMP280_NormalMode(void);  //Note:must be called before READ data!!!
uint8_t GET_BMP280_ID(void);
double GET_BMP280_Temperature(void);
double GET_BMP280_Pressure(void);

#ifdef __cplusplus
}
#endif
#endif /*__ BMP280_H */

/**
  * @}
  */

/**
  * @}
  */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
